from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-01 14:02:14.966555
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 01, May, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1325
Nobs: 643.000 HQIC: -49.5150
Log likelihood: 7875.68 FPE: 2.45783e-22
AIC: -49.7576 Det(Omega_mle): 2.13910e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325763 0.061785 5.273 0.000
L1.Burgenland 0.105122 0.039314 2.674 0.007
L1.Kärnten -0.110212 0.020616 -5.346 0.000
L1.Niederösterreich 0.196437 0.082128 2.392 0.017
L1.Oberösterreich 0.118537 0.081075 1.462 0.144
L1.Salzburg 0.258605 0.041788 6.189 0.000
L1.Steiermark 0.043828 0.054936 0.798 0.425
L1.Tirol 0.105250 0.044336 2.374 0.018
L1.Vorarlberg -0.063587 0.039169 -1.623 0.105
L1.Wien 0.026187 0.071827 0.365 0.715
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053105 0.132071 0.402 0.688
L1.Burgenland -0.032891 0.084038 -0.391 0.696
L1.Kärnten 0.040204 0.044067 0.912 0.362
L1.Niederösterreich -0.189196 0.175556 -1.078 0.281
L1.Oberösterreich 0.447872 0.173305 2.584 0.010
L1.Salzburg 0.285609 0.089325 3.197 0.001
L1.Steiermark 0.105693 0.117431 0.900 0.368
L1.Tirol 0.313857 0.094772 3.312 0.001
L1.Vorarlberg 0.021848 0.083727 0.261 0.794
L1.Wien -0.037607 0.153537 -0.245 0.807
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190268 0.031650 6.012 0.000
L1.Burgenland 0.090233 0.020139 4.480 0.000
L1.Kärnten -0.007928 0.010561 -0.751 0.453
L1.Niederösterreich 0.248874 0.042071 5.916 0.000
L1.Oberösterreich 0.157552 0.041532 3.794 0.000
L1.Salzburg 0.040412 0.021406 1.888 0.059
L1.Steiermark 0.025033 0.028142 0.890 0.374
L1.Tirol 0.086942 0.022712 3.828 0.000
L1.Vorarlberg 0.054084 0.020065 2.695 0.007
L1.Wien 0.116006 0.036794 3.153 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112354 0.031804 3.533 0.000
L1.Burgenland 0.045497 0.020237 2.248 0.025
L1.Kärnten -0.014340 0.010612 -1.351 0.177
L1.Niederösterreich 0.180708 0.042276 4.275 0.000
L1.Oberösterreich 0.327224 0.041733 7.841 0.000
L1.Salzburg 0.101608 0.021510 4.724 0.000
L1.Steiermark 0.110326 0.028278 3.901 0.000
L1.Tirol 0.098020 0.022822 4.295 0.000
L1.Vorarlberg 0.059374 0.020162 2.945 0.003
L1.Wien -0.021524 0.036973 -0.582 0.560
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114980 0.059207 1.942 0.052
L1.Burgenland -0.043139 0.037674 -1.145 0.252
L1.Kärnten -0.046229 0.019755 -2.340 0.019
L1.Niederösterreich 0.144552 0.078701 1.837 0.066
L1.Oberösterreich 0.157293 0.077692 2.025 0.043
L1.Salzburg 0.283678 0.040044 7.084 0.000
L1.Steiermark 0.055949 0.052644 1.063 0.288
L1.Tirol 0.165678 0.042485 3.900 0.000
L1.Vorarlberg 0.096528 0.037534 2.572 0.010
L1.Wien 0.072954 0.068829 1.060 0.289
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059742 0.046613 1.282 0.200
L1.Burgenland 0.030442 0.029660 1.026 0.305
L1.Kärnten 0.051550 0.015553 3.314 0.001
L1.Niederösterreich 0.206366 0.061961 3.331 0.001
L1.Oberösterreich 0.322801 0.061166 5.277 0.000
L1.Salzburg 0.038204 0.031526 1.212 0.226
L1.Steiermark 0.007049 0.041446 0.170 0.865
L1.Tirol 0.130462 0.033449 3.900 0.000
L1.Vorarlberg 0.064012 0.029551 2.166 0.030
L1.Wien 0.090216 0.054189 1.665 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173728 0.055961 3.104 0.002
L1.Burgenland 0.005847 0.035608 0.164 0.870
L1.Kärnten -0.065266 0.018672 -3.495 0.000
L1.Niederösterreich -0.096599 0.074386 -1.299 0.194
L1.Oberösterreich 0.203767 0.073433 2.775 0.006
L1.Salzburg 0.055135 0.037849 1.457 0.145
L1.Steiermark 0.239451 0.049758 4.812 0.000
L1.Tirol 0.501801 0.040156 12.496 0.000
L1.Vorarlberg 0.060898 0.035477 1.717 0.086
L1.Wien -0.076327 0.065056 -1.173 0.241
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147560 0.062067 2.377 0.017
L1.Burgenland 0.004865 0.039494 0.123 0.902
L1.Kärnten 0.060329 0.020710 2.913 0.004
L1.Niederösterreich 0.184059 0.082503 2.231 0.026
L1.Oberösterreich -0.062086 0.081445 -0.762 0.446
L1.Salzburg 0.208005 0.041978 4.955 0.000
L1.Steiermark 0.134474 0.055187 2.437 0.015
L1.Tirol 0.068558 0.044538 1.539 0.124
L1.Vorarlberg 0.144834 0.039348 3.681 0.000
L1.Wien 0.111311 0.072155 1.543 0.123
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378046 0.036539 10.347 0.000
L1.Burgenland -0.001127 0.023250 -0.048 0.961
L1.Kärnten -0.021791 0.012192 -1.787 0.074
L1.Niederösterreich 0.211463 0.048569 4.354 0.000
L1.Oberösterreich 0.226115 0.047946 4.716 0.000
L1.Salzburg 0.038780 0.024712 1.569 0.117
L1.Steiermark -0.013966 0.032488 -0.430 0.667
L1.Tirol 0.095105 0.026219 3.627 0.000
L1.Vorarlberg 0.052978 0.023164 2.287 0.022
L1.Wien 0.036567 0.042477 0.861 0.389
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036111 0.113742 0.173321 0.140938 0.102605 0.085318 0.037737 0.209968
Kärnten 0.036111 1.000000 -0.021277 0.134303 0.052611 0.090120 0.442169 -0.060531 0.092500
Niederösterreich 0.113742 -0.021277 1.000000 0.322965 0.130326 0.283885 0.075536 0.162364 0.296519
Oberösterreich 0.173321 0.134303 0.322965 1.000000 0.222263 0.310145 0.169011 0.150255 0.249851
Salzburg 0.140938 0.052611 0.130326 0.222263 1.000000 0.132331 0.097488 0.112842 0.130224
Steiermark 0.102605 0.090120 0.283885 0.310145 0.132331 1.000000 0.139956 0.120965 0.049371
Tirol 0.085318 0.442169 0.075536 0.169011 0.097488 0.139956 1.000000 0.069758 0.149704
Vorarlberg 0.037737 -0.060531 0.162364 0.150255 0.112842 0.120965 0.069758 1.000000 0.006644
Wien 0.209968 0.092500 0.296519 0.249851 0.130224 0.049371 0.149704 0.006644 1.000000